#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define y1 y_alpha_1

using namespace std;

using ll = long long;
using db = double;
using vec = vector<int>;
using pii = pair<int,int>;

int read() {
	int x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-',ch = getchar();
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48),ch = getchar();
	return f ? -x : x;
}

const int N = 1e5 + 10;

int d[N],mxd[N],fr[N],cent[N],top,n,m,fa[N],pos,vis[N];
vec G[N];

struct ST {
	int mx[2][22][N];
	int lg[N],pw[N];
	void build() {
		for(int i = 2;i <= top;i++) lg[i] = lg[i >> 1] + 1;
		for(int i = (pw[0] = 1);i <= lg[top];i++) pw[i] = pw[i - 1] << 1;
		for(int k = 1;k <= lg[top];k++)
			for(int i = 1;i + pw[k] - 1 <= top;i++)
				for(int d = 0;d < 2;d++)
					mx[d][k][i] = max(mx[d][k - 1][i],mx[d][k - 1][i + pw[k - 1]]);
	}
	int query(int x,int y,int d) {
		if(x > y) return -n; int k = lg[y - x + 1];
		return max(mx[d][k][x],mx[d][k][y - pw[k] + 1]);
	}
}S;

void dfs(int x,int p) {
	fa[x] = p; d[x] = d[p] + 1; if(pos == 0 || d[x] > d[pos]) pos = x;
	for(auto y : G[x])
		if(y != p) dfs(y,x); 
}

void get(int x,int p,int pos) {
	fa[x] = p; fr[x] = pos; mxd[pos] = max(mxd[pos],d[x]);
	for(auto y : G[x])
		if(y != p && !vis[y]) d[y] = d[x] + 1,get(y,x,pos);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in; for(int i = 1,u,v;i < n;i++) u = in,v = in,G[u].pb(v),G[v].pb(u);
	dfs(1,0); int st = pos; pos = 0; dfs(st,0); int ed = pos; cent[++top] = ed; while(ed != st) ed = fa[ed], cent[++top] = ed;
	for(int i = 1;i <= top;i++) vis[cent[i]] = 1;
	for(int i = 1;i <= top;i++) d[cent[i]] = 0,get(cent[i],0,i); for(int i = 1;i <= top;i++) S.mx[0][0][i] = mxd[i] - i, S.mx[1][0][i] = mxd[i] + i;
	S.build();
	m = in;
	while(m--) {
		int x = in,y = in; if(fr[x] > fr[y]) swap(x,y);
		int ans;
		if(fr[x] == fr[y]) { ans = min(d[x],d[y]) + max(top - fr[x],fr[x] - 1); }
		else {
			int mid = (fr[x] - d[x] + fr[y] + d[y]);
			if(fr[x] * 2 >= mid) { ans = max(fr[y] - 1,top - fr[y]) + d[y]; }
			else if(fr[y] * 2 <= mid) { ans = max(fr[x] - 1,top - fr[x]) + d[x]; }
			else {
				ans = max(S.query(fr[x] + 1,mid >> 1,1) - fr[x],fr[x] - 1) + d[x];
				ans = max(ans,max(fr[y] + S.query((mid >> 1) + 1,fr[y] - 1,0),top - fr[y]) + d[y]);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}
